package com.hangzhou.welbeing.welbeinginstrument.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.bean.FansBean;
import com.hangzhou.welbeing.welbeinginstrument.config.RBConstants;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;
import com.hangzhou.welbeing.welbeinginstrument.tool.GlideCircleTransform;

import java.util.ArrayList;
import java.util.List;

/**
 * 时间 2017 年 09 月 22.
 * 作者 Administrator  刘传华
 * 公司 杭州惟君医疗科技有限公司
 * 包名 com.hangzhou.welbeing.pregnant.welbeing_pregnant.adapter
 * 工程名 welbeing_pregnant
 */
public class FansAdapte  extends  RecyclerView.Adapter<FansAdapte.ViewHolder> implements View.OnClickListener{
    private static final String TAG ="FansAdapte" ;
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private List<FansBean.DataBean> list = new ArrayList<>();
    private  Context mcontent ;
    public FansAdapte(List<FansBean.DataBean> mlist, Context content) {
        list.addAll(mlist);
        mcontent = content;

    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_fans_recyclerview,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        view.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv_name.setText(list.get(position).cus_name);
        Glide.with(mcontent).load(RBConstants.SERVER_URL+"/Public/Uploads/"+list.get(position).cus_logo).transform(new GlideCircleTransform(mcontent)).into(holder.iv_head_portrait);
        Log.e(TAG,"onBindViewHolder==========>"+RBConstants.SERVER_URL+"/Public/Uploads/"+list.get(position).cus_logo);
        int att = list.get(position).att;
        if(att == 1){
            holder.tv_state.setText("已关注");
        }else if(att == 2){
            holder.tv_state.setText("互相关注");
        }


        String state = list.get(position).state;
        if(state.equals("1")){
            holder.tv_content.setText("怀孕中");
        }else if(state.equals("0")){
            holder.tv_content.setText("备孕中");
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void onClick(View v) {
        if(mOnItemClickListener != null ){
            mOnItemClickListener.onItemClick(v);
        }
    }
    /**
     * 身体布局Holder
     */
    static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView tv_name;
        private  TextView tv_content;
        private  TextView tv_state;
        private ImageView iv_head_portrait;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_name =  (TextView) itemView.findViewById(R.id.item_fans_recyclerview_tv_name);
            tv_content =  (TextView) itemView.findViewById(R.id.item_fans_recyclerview_tv_content);
            tv_state =  (TextView) itemView.findViewById(R.id.item_fans_recyclerview_tv_state);
            iv_head_portrait =  (ImageView) itemView.findViewById(R.id.item_fans_recyclerview_iv_head_portrait);
        }
    }
}
